﻿using LxBasic;

namespace LxCore.Samples
{
    public class CylinderNaturalConvection : SampleVMBase
    {
        public CylinderNaturalConvection()
        {
            this.Name = "圆柱自然对流";
            this.FileName = "圆柱绕流.msh";
        }
        public override void RunCase()
        {
            ReadFile();
            LxSim.Sim.Info.ProjName = Name;
            var phy_air = LxSim.Sim.Physics.CreatePhysicalModel();
            phy_air.Name = "空气";
            phy_air.PhysicalType = PhysicalTypes.流体;
            phy_air.IsEnergyEnabled = true;
            phy_air.BuoyancyType = BuoyancyTypes.Boussinesq模型;
            phy_air.ReferenceValue.Gravity = new ConstField.Vector(new Vector3d(0, -9.8, 0)); 
            var phy_al = LxSim.Sim.Physics.CreatePhysicalModel();
            phy_al.Name = "铝";
            phy_al.PhysicalType = PhysicalTypes.固体;
            phy_al.IsEnergyEnabled = true;

            var z_air = FindZone("AIR");
            ResHelper.GetCond(z_air).PhysicalModel = phy_air;

            var x1 = FindBound(z_air, "X+");
            var x1Cond = ResHelper.GetCond(x1);
            x1Cond.BoundType = BoundTypes.压力出口;
            var x2 = FindBound(z_air, "X-");
            var x2Cond = ResHelper.GetCond(x2);
            x2Cond.BoundType = BoundTypes.压力出口;

            var inlet = FindBound(z_air, "Y-");
            var inletCond = ResHelper.GetCond(inlet);
            inletCond.BoundType = BoundTypes.压力出口;

            var sym = FindBound(z_air, "SYMMETRY");
            var symCond = ResHelper.GetCond(sym);
            symCond.BoundType = BoundTypes.对称面;

            var outlet = FindBound(z_air, "Y+");
            var outletCond = ResHelper.GetCond(outlet);
            outletCond.BoundType = BoundTypes.压力出口;

            var z_al = FindZone("AL");
            var z_al_cond = ResHelper.GetCond(z_al);
            z_al_cond.PhysicalModel = phy_al;
            z_al_cond.EnergySource_b = new ConstField.Double(1000);
            var al_sym = FindBound(z_al, "SYMMETRY-AL");

            var graph = LxSim.Sim.Visuals.CreateGraph("流场");
            graph.GraphType = GraphTypes.矢量图;
            graph.ScalarType = ScalarFieldTypes.Velocity;
            graph.SetSelector(z_air.Inner, true);

            graph = LxSim.Sim.Visuals.CreateGraph("MassImbalance");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.MassImbalance;
            graph.SetSelector(sym, true);

            graph = LxSim.Sim.Visuals.CreateGraph("温度");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.Temperature;
            graph.SetSelector(sym, true);
            graph.SetSelector(al_sym, true);

            graph = LxSim.Sim.Visuals.CreateGraph("Pressure");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.Pressure;
            graph.SetSelector(sym, true);
            graph.SetSelector(inlet, true);
            graph.SetSelector(outlet, true);
            LxSim.Sim.Steps.IterationStep.MaxStepRule.MaxStep = 200;
            MultiThreads.SetThreadsCount(3);
            RunSimulation();
        }
    }
}
